<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/plateform/include/common-base.jsp"%>
  <title>通用代码集</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">
  <!-- top start -->
  <%@include file="/common/plateform/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/plateform/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
  
  
  <!-- 
  		<br/>
		<ol class="breadcrumb bgblue">
			<li>
				<span class="label label-danger font14" >系统管理 /数据字典管理</span>
			</li>
		</ol>
	 -->	
    <!-- Main start -->

<section class="content">
      <div class="row">
        <div class="col-xs-12">
			<div class="box box-info">
				<!--搜索title  start -->
				<div class="box-header with-border">
					<h3 class="box-title"><i class="fa fa-search"></i>数字字典查询搜索</h3>
					<div class="box-tools pull-right">
						<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
						</button>
						<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
					</div>
				</div>
				<!--搜索title  end -->
				<div class="box-body">
					<form id="searchForm" class="form-horizontal">
						<input type="hidden" name="doCode" value="dictCateList"/>
						<input type="hidden" name="sysEname" value="default"/>
						<div class="form-group">
							<div class="col-sm-2 text-right"><label class="control-label" >科目名称：</label></div>
							<div class="col-sm-3">
								<input type="text" class="form-control clean"  name="cateCname" value="" />
							</div>
							<div class="col-sm-2 text-right"><label class="control-label" >科目标识：</label></div>
							<div class="col-sm-3">
								<input type="text" class="form-control clean"  name="cateEname" value="" />
							</div>
						</div>
						<center>
							<div class="box-footer clearfix">
								<button type="button" class="btn btn-success" onclick="getTableData();"><i class="fa fa-search"></i> 查询</button>&nbsp;&nbsp;
								<button  type="button" class="btn btn-warning" onclick="mytools.cleanData('#searchForm');">重置 </button>
							</div>
						</center>
					</form>
				</div>
			</div>

          <div class="box box-success">
            <div class="box-header">
               <h3 class="box-title"><i class="fa fa-user"></i> 数字字典列表 共计<span id="dataListTotalCount">0</span>条数据
				   &nbsp;&nbsp;&nbsp;&nbsp;
				   <button class="btn btn-primary" type="button" onclick="toAdd('parent');"><i class="fa fa-plus-circle"></i> 增加</button>
			   </h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">

              <table id="example" class="table table-bordered " >
                <thead>
                <tr>
              	  <th>科目名称</th>
                  <th>科目标识</th>
                  <th>状态</th>
                  <th>描述</th>
                  <th>所属系统</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody id="myList">
                </tbody>
              </table>
                <center>
    	  			  <ul id="pageList"></ul>
        		</center>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- Main end -->
    
    
      <!-- foot start -->
  <div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">科目信息</font>&nbsp;</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="orgForm">
							<input type="hidden" name="formToken" id="formToken" value="${formToken}"/>
							<input type="hidden" name="cateId" id="cateId" class="clean" value="${item.cateId}"/>
							<input type="hidden" name="oldCateEname" id="oldCateEname" value="${item.cateEname}"/>
							<input type="hidden" name="sysEname" value="default"/>
						    <input type="hidden" name="doCode" value="dictCateSave"/>
							 <div class="box-body" id="orgFormData">
			                <div class="form-group">
			                  <label  class="col-sm-4 control-label" >科目中文名称</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control clean" id="cateCname"  name="cateCname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-4 control-label">科目标识</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control clean" id="cateEname" name="cateEname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-4 control-label">描述</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control clean" id="cateRemark" name="cateRemark" placeholder="">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-4 control-label">状态</label>
			                  <div class="col-sm-6">
			                    <input type="radio" checked="checked" value="1" name="cateStatus"> <i></i> 启用 
                                <input type="radio" value="0" name="cateStatus"> <i></i> 停用
			                  </div>
			                </div>
							 <div class="form-group">
								 <label class="col-sm-4 control-label">显示类型</label>
								 <div class="col-sm-6">
									 <select name="viewType" class="form-control" style="width:100px;">
										 <option value="">--默认--</option>
										 <option value="1">三级联动</option>
									 </select>
									 <div class="f12">注：目前只支持级联才选，其他默认</div>
								 </div>
							 </div>

			              </div>
			               <div class="box-footer">
			                <button type="button" class="btn btn-primary pull-left" onclick="cannel();">取消</button>
			                <button type="button" class="btn btn-primary pull-right" onclick="save('orgForm');">提 交</button>
			              </div>
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  
    
    
    
    
    
    <div class="modal fade" id="my_modal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:1020px;">
		   	<div class="modal-content" id="dataItemManager" ></div>
		</div>
	</div> 
	<script type="text/template" id="dataList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr id=<?=rows[i].cateId?> >
					<th style="display:none;"><?=rows[i].cateId?></th>
					<td><?=rows[i].cateCname?></td>
					<td><?=rows[i].cateEname?></td>
					<td><?if("1"==rows[i].cateStatus){?><font color=blue>启用</font>
                        <?}else{?><font color=red>停用</font><?}?>
                    </td>
					<td><?=rows[i].cateRemark?></td>
					<td><?=rows[i].sysEname?></td>
                    <td>
						<button class="btn btn-primary btn-xs" type="button" onclick="itemTrees('<?=rows[i].cateEname?>','<?=rows[i].cateCname?>');">条目管理</button>&nbsp;
						<button class="btn btn-warning btn-xs" type="button" onclick="toEdit('<?=rows[i].cateId?>');">修改</button>&nbsp;
						<button class="btn btn-danger btn-xs" type="button" onclick="del('<?=rows[i].cateId?>');">删除</button>
					</td>
				</tr>
     		<?}?>
	</script>
	<script>
var clickMenu= 'sys-dict-list';
var id;
var cateEname;
$(function () {
	getTableData();
	$('#example tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }  else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     id = $('tr.selected th').eq(0).html();
	     cateEname = $('tr.selected td').eq(1).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );
  });
  
//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'hide.bs.modal' ,function(e){  
    mytools.cleanData("#orgFormData");
}); 

//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'show.bs.modal' ,function(e){  
	$.ajax({ type:'post',url:'${ctx}/sendPage/token?token=true', dataType:'json',
	    success: function(myData){
	    	//console.log(myData);
		  $('#formToken').val(myData);
	  	}
	});	
}); 


function getTableData(){
	$.ajax({url:common_list_url,type: "get",dataType: "json",
			data:$('#searchForm').serialize()+getCurrentPage(dictUrl+"?"+$('#searchForm').serialize(),8),
	        error: function(){   layer.msg('查询失败'); },
		   success: function(myData){
	            $("#dataListTotalCount").text(myData.total);
				var data = baidu.template('dataList',myData);
				$("#myList").html(data);
			  	var option= {ele:$("#pageList")[0],total:myData.total,fn:getTableData,
					url:dictUrl+"?"+$('#searchForm').serialize()}
				generatePages(option);
		   }
		});	
  }
  
  
function toAdd(){
	$('#my_modal').modal('show');
	setToken();
    mytools.cleanData('#orgForm');
    $("#orgForm").find("input[name='cateEname']").attr("readonly",false);
}

function itemTrees(code,cname){
	$("#dataItemManager").load("${ctx}/template/uct/dict-detail.html",function(){loadItems(code,cname);});
	$('#my_modal2').modal('show');
}

function toEdit(id){
	if(id=="undefined" || id =="" || id == null){
		layer.alert('请先选中一条数据！', {
		    skin: 'layui-layer-molv'
		    ,closeBtn: 0
		  });
		return;
	}else{
		$.ajax({type:'get', url:common_info_url, dataType:'json',
		    data:{'cateId':id,'doCode':'dictCateInfo'},
		    success: function(myData){
		    	 //console.log(myData);
                mytools.cleanData('#orgForm');
				 FormUtil.fillData("#orgForm", myData,"id");
				 DictUtil.checkRadioDict("cateStatus", myData.cateStatus);
				 $("#orgForm").find("input[name='cateEname']").attr("readonly",true);
                $('#my_modal').modal('show');
				 setToken();
		  	}
		});	
	}
	//$('#my_modal').modal('show');
}

function del(id){
	if(id=="undefined" || id =="" || id == null){
		layer.alert('请先选中一条数据！', {skin: 'layui-layer-molv' ,closeBtn: 0 });
		return;
	}else{
		layer.confirm('您确认要进行删除操作？', { btn: ['确认','取消'] }, 
		   function(){
				$.ajax({type:'post', url:common_submit_url, dataType:'json',
				    data:{'cateId':id,'doCode':'dictCateDel'},
				    success: function(myData){
				    	if(myData.flag=='T'){
				    		layer.alert('操作成功！', {skin: 'layui-layer-molv',closeBtn: 0 });
				    		id = "";
				    		refresh();
				    	}else{
				    	    layer.alert("操作失败！"+myData.msg);
						}
				  	}
				});	
			}, 
		   function(){}
		);
	}
}
function save(formId){
	if(!$("#" + formId)[0].checkValidity()){
		alert("请先完善必输项和必选项！");
		return ;
	}
	$.ajax({ type:'post',url:common_submit_url,dataType:'json',
	    data:$("#"+formId).serialize(),
	    success: function(myData){
	    	//console.log(myData);
	    	if(myData.flag=='T'){
	    		layer.alert('操作成功！', {skin:'layui-layer-molv',closeBtn:0});
	    		$('#my_modal').modal('hide');
	    		refresh();
	    	}else{
	    		alert(myData.msg);
	    	}
	  	}
	});	
}

function cannel(){
	$('#my_modal').modal('hide');

}
function deleteAllRow(){
	var tb = document.getElementById('example');
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}

function refresh(){
    //window.location.reload();
	getTableData();
}
function setToken(){
	$.ajax({ type:'get',url:'${ctx}/sendPage/token?token=true',dataType:'text',
	    success: function(myData){
		   $('#formToken').val(myData);
	  	}
	});	
}
</script>
	
    
  </div>
  <!-- /.content-wrapper -->
  <!-- foot start -->
       
  <%@include file="/common/plateform/foot.jsp" %>
  <!-- foot start -->
  


  
</body>
	



</html>
